from flask import g

class PermissionStr:
    READ = 'read'
    DELETE = 'delete'
    WRITE = 'write'
    ROOT = 'root'

    @classmethod
    def default(cls):
        return ':'.join([cls.READ, cls.WRITE, cls.DELETE])

    @classmethod
    def can_do_permissions(cls, permissions):
        return permissions in g.user.auths

class PermissionBinary:
    READ = 0b00000001  # 0x01
    COMMENT = 0b00000010  # 0x02
    WRITE = 0b00000100  # 0x04
    ADMINISTER = 0b00001000  # 0x08

    @classmethod
    def default(cls):
        return cls.READ | cls.COMMENT

    @classmethod
    def can_permissions(cls, permissions):
        return (g.user.permissions & permissions) == permissions

